package com.mail.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mail.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    /**
     * 根据用户名查询用户
     *
     * @param username
     * @return
     */
    @Select("select * from t_user where username = #{username} and enabled = 1")
    User queryUserIdByUserName(@Param("username") String username);

    /**
     * 根据用户名查询用户
     *
     * @param username
     * @return
     */
    @Select("select password from t_user where username = #{username} and enabled = 1")
    String queryPasswordByUserName(@Param("username") String username);

    /**
     * 查询某个团队下的成员
     *返回信息：username,nickname,img
     */
    @Select("select id,username,nickname,img from t_user where id in (select member_id from team_member where team_id=#{teamId}) limit #{firstIndex},#{lengths}")
    List<User> queryUserByTeamId(@Param("teamId")long teamId, @Param("firstIndex") int firstIndex, @Param("lengths")int lengths);

    @Select("select count(*) from t_user where id in (select member_id from team_member where team_id=#{teamId})")
    long queryUserByTeamIdCount(@Param("teamId")long teamId);

    /**
     * 根据用户名查询用户id
     *
     * @param username
     * @return
     */
    @Select("select id from t_user where username = #{username} and enabled = 1")
    Long queryIdByUserName(@Param("username") String username);
}
